define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'userlevelrecord/index',
                    add_url: 'userlevelrecord/add',
                    edit_url: 'userlevelrecord/edit',
                    del_url: 'userlevelrecord/del',
                    multi_url: 'userlevelrecord/multi',
                    table: 'user_level_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'merid', title: __('Merid')},
                        {field: 'user.username', title: __('User_id'),operate:"LIKE %...%"},
                        {field: 'admin.username', title: __('Admin_id'), operate:'LIKE %...%'},
                        {field: 'old_level', title: __('Old_level'), visible: false, searchList:{0:'普通会员',1:'报单中心',2:'代理商',3:'分公司',4:'运营中心'}},
                        {field: 'old_level_text', title: __('Old_level'), operate:false},
                        {field: 'new_level', title: __('New_level'), visible: false, searchList:{0:'普通会员',1:'报单中心',2:'代理商',3:'分公司',4:'运营中心'}},
                        {field: 'new_level_text', title: __('New_level'), operate:false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'remark', title: __('Remark')},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});